library("plyr")
library("ggplot2")
library("fUnitRoots")

data<-week_de("product_1")
data<-week_de("product_2")
data<-week_de("product_3")
tmp<-data$p$all-data$r$all
#tmp2<-tmp["950756",]
tmp<-tmp[data$pr$full=="h"&data$pr$median=="h"&data$pr$zero=="h",]
urdfTest(ts[[1]]$x)
length(tmp[1,])
wts<-ts(tmp[4,],start = 16,end=c(28,4),frequency = 4)
timed_t<-decompose(wts)
plot(timed_t)
acf(timed_t$x,lag.max = 20)
pacf(timed_t$x,lag.max = 20)
pp<-list()
pp[[1]]<-timed_t
lg<-plts(ts=pp,lag.max=40,lgval=0.15,dif=4,sen=FALSE,diff=0)
lg[[2]]
lg<-plts(ts=pp,lag.max=40,lgval=0.15,dif=4,sen=TRUE,diff=0)
lg[[2]]
myaim_wk(data=tmp,id=4,start=17,end=28,k=4)




ts<-lgts(tmp,n=1,start=16,end=28,k=4)
#plot(lgem(data=ts[[1]]$x,cyc=4))
lg<-plts(ts=ts,lag.max=100,lgval=0.15,dif=16,sen=FALSE,diff=0)
lg[[2]]
myaim(data=tmp,id=1,start=17,end=28,k=4)





ts.plot(sadas)

#这里开始利用特殊序列进行非线性拟合
y<-lgemc(data=ts[[1]]$x,cyc=6)
if(which.max(y[,2])!=length(y[,2])){
  ymax <- y[c((which.max(y[,2])+1):length(y[,2]),1:which.max(y[,2])),]
}else{
  ymax <- y
}
model <- lm(ymax[,2] ~ poly (1:length(ymax[,2]),6))
plot(1:length(ymax[,2]),ymax[,2], type = "l")
#model <- lm(y ~ poly(x, 2))
#
plot(ymax[,2], type = "l")
lines(fitted(model),col = 2)
yfit<-cbind(ymax,fitted(model))
yfit_sort<-yfit[order(yfit[,1]),]
yfit_s4<-matrix(matrix(c(1,1,1,1,1,1),nrow=6)%*%matrix(yfit_sort[,3],nrow=1),ncol=1)
tsx<-ts[[1]]$x-yfit_s4
plot(tsx,type="l")
tsx<-ts(tsx,start = 16,end=c(28,24),frequency = 24)
timed_t<-decompose(tsx)
plot(timed_t)
pacf(tsx,lag.max = 150)
pp<-list()
pp[[1]]<-timed_t
plts(ts=pp,lag.max=100,lgval=0.15,dif=24,sen=TRUE,diff=0)
ARIMA<-arima(timed_t$x,order = c(6,0,0),seasonal=list(order=c(2,1,1),period=24),method = "CSS")
pre=predict(ARIMA,n.ahead=24)
pre$pred<-pre$pred+yfit_s4[1:24]
plot(ymax)

plot(1:52,ymax[,2], type = "l")
model <- lm(y$数量 ~ poly (1:52,10))
plot(1:52,ymax[,2], type = "l")
#model <- lm(y ~ poly(x, 2))
#plot(y, type = "l")
lines(fitted(model),col = 2)
fitted(model)
#x=poly (1:54,4)
#y=32+x%*%c(3,141,-1.24,94)





install.packages("portfolio")
library(portfolio)
data(dow.jan.2005)
map.market(id    = dow.jan.2005$symbol,
           area  = dow.jan.2005$price,
           group = dow.jan.2005$sector,
           color = 100 * dow.jan.2005$month.ret)
n=10
wtest<-function(n=3){
test<-cbind(1:n,abs(rnorm(n)))
test1<-test[order(test[,2]),]
map.market(id = w1,group = w1,area = w1,color=w1,lab = c(group = FALSE,id = TRUE))
}
w1<-as.data.frame(c(100,200,300,350,400,450,500))
colnames(w1)<-"data"
wtest(n=2)
cumsum(c(1,2,3
         ))

install.packages("treemap")
library(treemap)
data(GNI2010)
treemap(GNI2010,
        index=c("continent", "iso3"),
        vSize="population",
        vColor="GNI",
        type="value")
colnames(GNI2010)
treemap(w1,
        index="data",
        vSize="data",
        vColor="data",
        type="value")
